package com.example.app.api;

import com.example.app.common.Result;
import com.example.infra.mapper.MenuMapper;
import com.example.infra.mapper.RoleMapper;
import com.example.infra.po.MenuPo;
import com.example.infra.po.RolePo;
import com.example.app.security.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/me")
@RequiredArgsConstructor
public class MeController {

    private final RoleMapper roleMapper;
    private final MenuMapper menuMapper;

    @GetMapping("/roles")
    public Result<List<RolePo>> myRoles() {
        Integer userId = SecurityUtils.getCurrentUserId();
        return Result.success(roleMapper.selectByUserId(userId));
    }

    @GetMapping("/menus")
    public Result<List<MenuPo>> myMenus() {
        Integer userId = SecurityUtils.getCurrentUserId();
        return Result.success(menuMapper.selectByUserId(userId));
    }
}


